// pages/singer/singer.js
const {getSingerList} = require('../../service/singer')

Page({
  data: {
    singerlist: [],
    scrollTop: 0
  },
  onLoad: function () {
    this.getHotSingers()
  },
  // 获取歌手数据，服务器返回了100条，但是我们只渲染30个
  async getHotSingers() {
    const res = await getSingerList()
    if (res === 'error') return
    const singerlist = res.singers
    console.log(singerlist)
    if (!singerlist.length) return
    wx.showLoading({title: '加载歌手中...'})
    this.setData({
      singerlist
    }, () => wx.hideLoading())
  },
  // 接受组件传来的滚动值，并滚动到指定位置
  onScrollTo(e) {
    console.log(e)
    const {scrollTop} = e.detail
    wx.pageScrollTo({scrollTop})
  },
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  }
})